package textui;

import static hacked.ReduceVerbosity.println;
import static hacked.ReduceVerbosity.range;
import static hacked.ReduceVerbosity.readInt;
import static hacked.ReduceVerbosity.tolist;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ElementSelector<T> {
	private List<T> _data;
	
	public ElementSelector(List<T> map) {
		_data = map;
	}
	public T select() {
		if(_data.size()==0)
			return null;
		Map<Integer, T> map = new HashMap<Integer, T>();

		for (int i : range(_data.size())) {
			map.put(i, _data.get(i));
			println(i + "\t:" + _data.get(i));
		}
		while(true)
		{
			try{
				T t =map.get(readInt());
				return t;
			}catch(Exception e)
			{
				println("invalid input, try again");
			}
		}
		
	}
	public static final class ReduceVerbosity{
		public static final <T> SelectorElement<T> element(T t,String s)
		{
			return new SelectorElement<T>(t, s);
		}
	}
	public static void main(String[] args) {
		final String s = "abra";
		final String a = "xaf";
		UIElement string = new ElementSelector<UIElement>(tolist(new UIElement(null) {
			@Override
			public String toString()
			{
				return s;
			}
			@Override
			public UIElement run() {
				// TODO Auto-generated method stub
				return null;
			}
		},new UIElement(null) {
			@Override
			public String toString()
			{
				return s;
			}
			@Override
			public UIElement run() {
				// TODO Auto-generated method stub
				return null;
			}
		})).select();
		println(string);
	}
	
}
